var express = require('express');
var router = express.Router();
var superagent = require('superagent');
var logger = require('../log4j').logger;
var logger_error = require('../log4j').logger_error;

router.get('/shorttv', function(req, res, next) {
    var thisUrl = req.url;
    var isApp = req.query.isApp;
    console.log(isApp);
    var shareUrl = encodeURIComponent((global.browserURL +'/banner'+thisUrl).split('#')[0]);
    console.log((global.browserURL +'/xmas'+thisUrl).split('#')[0]);
    superagent
    .get(global.wechatURL + '/wechat_api/jsconfig?url=' + shareUrl)
    .end(function(err2, res2) {
      if (res2 !== undefined && res2.ok) {
        res2.body.browserUrl = global.browserURL;
        res2.body.isApp = isApp;
        res.render('banner/shorttv',res2.body);
      } else {
        logger_error.error('xmas.js.......微信分享api错误。'+JSON.stringify(err2));
        console.error('微信分享api错误。');
      }
    });
});

module.exports = router;
